package artid.com.arttogo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.AuctionInformationParser;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;

/**
 * 
 *    
 * 项目名称：ArtworkArt   
 * 类名称：AuctionInformation_Activity   
 * 类描述：拍卖会-拍卖会详情-拍卖会详细信息   
 * 创建人：耿卫斌   
 * 创建时间：2017-3-3 上午10:53:42   
 *
 */
public class AuctionInformation_Activity extends BaseActivity implements OnClickListener {
	private ImageView title_rightBtn;
	private TextView previewTime,previewAddress,auctionTime,auctionAddress,historicalTurnover,turnoverRate,
	auctionTitle,auctionNum,specialNum,lotNum,auctionCompany,auctionAddress2;
	private LinearLayout auctionHouse;
	private ImageView auctionImg;
	private AuctionInformationParser mAuctionInformationParser;
	private String auctionID;//拍卖会ID
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_auctioninformation);
		initView();
	}
	private void initView(){
		mContext=AuctionInformation_Activity.this;
		auctionID=getIntent().getStringExtra("auctionID");
		mBack = (ImageView) findViewById(R.id.back_btn);
		mBack.setOnClickListener(this);
		mTittle = (TextView) findViewById(R.id.tittle_text);
		mTittle.setText("拍卖会详细信息");
		title_rightBtn=(ImageView) findViewById(R.id.share_collection_detail);
		title_rightBtn.setVisibility(View.GONE);
		title_rightBtn.setOnClickListener(this);
		previewTime=(TextView) findViewById(R.id.AuctionInformation_PreviewTime);
		previewAddress=(TextView) findViewById(R.id.AuctionInformation_PreviewAddress);
		auctionTime=(TextView) findViewById(R.id.AuctionInformation_auctionTime);
		auctionAddress=(TextView) findViewById(R.id.AuctionInformation_auctionAddress);
		historicalTurnover=(TextView) findViewById(R.id.AuctionInformation_HistoricalTurnover);
		turnoverRate=(TextView) findViewById(R.id.AuctionInformation_TurnoverRate);
		auctionHouse=(LinearLayout) findViewById(R.id.AuctionInformation_auctionHouseLL);
		auctionHouse.setOnClickListener(this);
		auctionImg=(ImageView) findViewById(R.id.AuctionInformation_auctionImg);
		auctionTitle=(TextView) findViewById(R.id.AuctionInformation_auctionTitle);
		auctionNum=(TextView) findViewById(R.id.AuctionInformation_auctionNum);
		specialNum=(TextView) findViewById(R.id.AuctionInformation_specialNum);
		lotNum=(TextView) findViewById(R.id.AuctionInformation_lotNum);
		auctionAddress2=(TextView) findViewById(R.id.AuctionInformation_auctionAddress2);
		getData();
	}
	@Override
	public void onClick(View v) {
		Intent intent;
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back_btn:
			finish();
			break;
		case R.id.share_collection_detail:
			//标题右按钮
			if(mAuctionInformationParser!=null){
				AuctionInformationParser.AuctionInformation_AuctionInfo auctioninfo = mAuctionInformationParser.getAuctioninfo();
				String content="预展:"+auctioninfo.getPreview_start_time()+"-"+auctioninfo.getPreview_end_time()
						+"/"+auctioninfo.getPreview_address()+"/"+"拍卖:"+auctioninfo.getAuction_start_time()
						+"-"+auctioninfo.getAuction_end_time()+"/"+auctioninfo.getAuction_address();
			AppUtil.shareAuction(mContext, "2", auctioninfo.getTitle(), content, "这里填写图片地址",
						"http://www.baidu.com", auctioninfo.getId(), true);
			}
			break;
		case R.id.AuctionInformation_auctionHouseLL:
			//拍卖机构
			intent=new Intent(mContext,AucOrgDetActivity.class);
			intent.putExtra("id", mAuctionInformationParser.getJigouinfo().getId());
			startActivity(intent);
			break;

		default:
			break;
		}
	}

	/**
	 * 获取拍卖会详情信息数据
	 */
	private void getData(){
		VolleyBasic.getInstance(this).post(Cache.auctionMsg,
				VolleyMap.getInstance().auctionMsg(auctionID),
				AuctionInformationParser.class, new VolleyCallback() {

			@Override
			public void onSuccess(VolleyData vd) {
				// TODO Auto-generated method stub
				AuctionInformationParser bean=(AuctionInformationParser) vd.getData();
				mAuctionInformationParser=bean;
				previewTime.setText(bean.getAuctioninfo().getPreview_start_time()+"-"+bean.getAuctioninfo().getPreview_end_time());
				previewAddress.setText(bean.getAuctioninfo().getPreview_address());
				auctionTime.setText(bean.getAuctioninfo().getAuction_start_time()+"-"+bean.getAuctioninfo().getAuction_end_time());
				auctionAddress.setText(bean.getAuctioninfo().getAuction_address());
				historicalTurnover.setText(bean.getAuctioninfo().getUnit()+" "+bean.getAuctioninfo().getTurnover());
				turnoverRate.setText(bean.getAuctioninfo().getTurnoverrate()+"%");
				Glide.with(mContext).load(bean.getJigouinfo().getImgurl()
						+ "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /3) + "x10.png"
						).asBitmap().centerCrop()
						.placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
						.into(new MyBitmapImageViewTarget(auctionImg));
				auctionTitle.setText(bean.getJigouinfo().getSeller_name());
				auctionNum.setText("拍卖会"+bean.getJigouinfo().getAuction_num()+"场");
				specialNum.setText("专场"+bean.getJigouinfo().getSpecial_num()+"个");
				lotNum.setText(bean.getJigouinfo().getLotrecord_num()+"件备案 / "+bean.getJigouinfo().getLot_num()+"件拍品");
				auctionAddress2.setText(bean.getJigouinfo().getAddress());
			}

			@Override
			public void onError(VolleyError volleyError) {
				// TODO Auto-generated method stub
			}
		});
	}
}
